/*

	This file prepares regressions sample at firm-product-destination-year level with grpuped support categories

*/

cd ${work}5_reg_analysis

use jurnr vnr land year unit vrd_exp_exsmall quantity using input\export_ipdt if year>2002 & vrd_exp_exsmall!=. , clear

*PROMOTION
destring jurnr, gen(jurnr_num)
merge m:1 jurnr_num land year using input\promotion_idt, keep(1 3) keepusing(treated_2 tdcinitiative_2) nogen
merge m:1 jurnr_num land year using input\promotion_product_idt, keep(1 3) keepusing(treated_p*_2 tdcinitiative_p*_2) nogen
drop jurnr_num
foreach v of varlist treated_2 tdcinitiative_2 treated_p*_2 tdcinitiative_p*_2 {
    replace `v'=0 if `v'==.
}

lab var treated_p1_2	"Partner Search etc."
lab var treated_p2_2	"Fairs etc."
lab var treated_p3_2	"Intelligence etc."
lab var treated_p4_2	"Commercial Assistance"
lab var treated_p5_2	"Everything else"

*PRODUCT CODES
merge m:1 vnr using input\productcodes_p, assert(2 3) keep(3) keepusing(cn2) nogen

*SPECIFICATIONS
gen log_quantity = log(quantity)
gen log_price = log(vrd_exp_exsmall/quantity)

winsor2 log_quantity log_price , cuts(1 99) by(unit) replace

lab var log_quantity	"ln(EXQ)"
lab var log_price 		"ln(Price)"
 
*FEs
egen FPY=group(jurnr vnr year)
egen FPD=group(jurnr vnr land)
egen IDY=group(cn2 land year)
egen F=group(jurnr)
 
*SAVE
compress
save temp\regsample_product_ipdt, replace 